package edu.ynmd.bim.action;

import edu.ynmd.bim.vo.FormVo;
import edu.ynmd.bim.vo.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class PublicAction {

    @PostMapping("BMI")
    @ResponseBody
    public Result bMI(@RequestBody FormVo formVo) throws Exception{

        float sgf= Float.valueOf( formVo.getSg())  ;
        float tzf=Float.valueOf(formVo.getTz());

        float result=0.0f;
        result=tzf/(sgf*sgf);

        String resultstr="";

        if(result<18.5){
            resultstr="较轻";
        }
        else if(result>=18.5&&result<=23.9){
            resultstr="正常";
        }
        else if(result>=24&result<=27){
            resultstr="较重";
        }
        else if(result>=28&&result<=32){
            resultstr="肥胖";
        }

        else {
            resultstr="非常肥胖";
        }

        String suggest="";


        switch (resultstr){
            case "较轻":
                suggest="好好吃饭，补充营养";
                break;

            case "正常":
                suggest="指标正常，继续保持";
                break;
            case "较重":
                suggest="营养过盛，控制饮食";
                break;

            case "肥胖":
                suggest="注意身体，该减肥了";
                break;
            case "非常肥胖":
                suggest="身体为重，不要吃了";
                break;

        }

        Result ro=new Result();
        ro.setResult(result);
        ro.setResultstr(resultstr);
        ro.setSugguest(suggest);

        return ro;

    }

}
